//
//  StatusRetweetedCell.swift
//  Weibo10
//
//  Created by Leon on 15/10/21.
//  Copyright © 2015年 Leon. All rights reserved.
//

import UIKit

class StatusRetweetedCell: StatusCell {

    /// 视图模型
    override var viewModel: StatusViewModel? {
        didSet{

            retweetedLable.text = viewModel?.retweetedText
            
            ///  更新 图片约束
            pictureView.snp_updateConstraints { (make) -> Void in
                
                // 根据配图数量，决定配图视图的顶部间距
                let offset = viewModel?.thumbnailUrls?.count > 0 ? statusCellMargin : 0
                make.top.equalTo(retweetedLable.snp_bottom).offset(offset)
            }
        }
    }
        
        ///  构造函数
        override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
     
        }
        
        required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
        }
    
    // MARK: - 懒加载控件
    /// 背景按钮
    private lazy var backButton: UIButton = {
       
        let btn = UIButton()
        
        btn.backgroundColor = UIColor(white: 0.90, alpha: 1)
        
        return btn
    }()
    
    /// 转发标签
    private lazy var retweetedLable: UILabel = UILabel(title: "i first lao shilao shi dadij daih daiha daihda daihd daihlao shi dadij daih daiha daihda daihd daih dadij daih daiha daihda daihd daihh", color: UIColor.darkGrayColor(), fontSize: 14, screenInset: statusCellMargin)

}

// MARK: - 设置界面
extension StatusRetweetedCell {
    override func setupUI() {
        super.setupUI()
        // 1 添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(retweetedLable, aboveSubview: backButton)
        
        // 2 自动布局
        backButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(statusCellMargin)
            make.left.equalTo(contentView.snp_left)
            make.right.equalTo(contentView.snp_right)
            make.bottom.equalTo(footView.snp_top)
        }
        
        retweetedLable.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(backButton.snp_top).offset(statusCellMargin)
            make.left.equalTo(backButton.snp_left).offset(statusCellMargin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLable.snp_bottom).offset(statusCellMargin)
            make.left.equalTo(retweetedLable.snp_left)
            make.width.equalTo(300)
            make.height.equalTo(90)
        }

    }
}











